##############################################################
#Figure C4: Distribution of Risk Aversion and Gender in CCES 2014
##############################################################

data <- read.dta("./input/cces-subset.dta")

smalld <- data[,c("employed", "out_of_labour", "race_14", "risk", "dem14", "education", 
                  "female", "income", "income_quarters", "age")]

smalld$income <- as.factor(smalld$income)
smalld$income_quarters <- as.factor(smalld$income_quarters)
smalld$education <- as.factor(smalld$education)

data3 <- na.omit(smalld) ##taking out missing values 

data3.2 <- data3 %>% 
  group_by(female,risk) %>% 
  summarise(count=n()) %>% 
  mutate(perc=count/sum(count))

data3.2$female2 = factor(data3.2$female, levels=c(0,1), labels =c('Men','Women'))


ggplot(data3.2, aes(x=as.factor(risk), y=perc, group=as.factor(female), fill=as.factor(female))) +
  geom_bar(stat= "identity", position="dodge") + 
  scale_y_continuous(labels=percent) + 
  facet_grid(~female2)  +
  ylab("Percentage") + 
  xlab ("Risk Aversion")  + 
  theme_bw() + 
  theme(panel.background = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor =   element_blank(),
        legend.position = "none") + 
  scale_x_discrete(breaks=c(0,1,2,3),labels= c("Taker", "", "", "Averse"))  +
  scale_fill_manual(values=c("grey60", "grey60"))

ggsave("./figures/figc4.pdf")  